# -*- coding: utf-8 -*-
from models import *

class Config:
  @staticmethod
  def language_code():
    return Config.__get_config_string_value('language_code', 'en_us')

  @staticmethod
  def articles_to_display():
    return Config.__get_config_int_value('articles_to_display', 20)

  @staticmethod
  def display_last_n_days():
    return Config.__get_config_int_value('display_last_n_days', 1)

  @staticmethod
  def feed_retrieval_delay_minutes():
    return Config.__get_config_int_value('feed_retrieval_delay_minutes', 1)

  @staticmethod
  def strip_html():
    return Config.__get_config_boolean_value('strip_html', False)

  @staticmethod
  def get_feeds():
    return Feed.all()

  @staticmethod
  def __get_config_int_value(key_name, default_value):
    config = ConfigValue.get_by_key_name(key_name)
    if config is None or config.value == '':
      return default_value
    else:
      return int(config.value)

  @staticmethod
  def __get_config_float_value(key_name, default_value):
    config = ConfigValue.get_by_key_name(key_name)
    if config is None or config.value == '':
      return default_value
    else:
      return float(config.value)
  
  @staticmethod
  def __get_config_boolean_value(key_name, default_value):
    config = ConfigValue.get_by_key_name(key_name)
    if config is None or config.value == '':
      return default_value
    else:
      return True if config.value == 'True' else False

  @staticmethod
  def __get_config_string_value(key_name, default_value):
    config = ConfigValue.get_by_key_name(key_name)
    if config is None or config.value == '':
      return default_value
    else:
      return str(config.value)
